package com.shuangti.gateway.server;

import com.shuangti.gateway.entity.LoginRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;



public class AuthService {

    private final WebClient webClient;

    public AuthService(WebClient.Builder webClientBuilder) {
        this.webClient = webClientBuilder.baseUrl("127.0.0.1:9100").build();
    }

    public Mono<String> getToken(String username, String password) {
        return webClient.post()
                .uri("/getToken")
                .contentType(MediaType.APPLICATION_JSON)
                .bodyValue(new LoginRequest(username, password))
                .retrieve()
                .bodyToMono(String.class);
    }
}
